<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
    <title>合作商列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <!-- load css -->
    <link rel="stylesheet" th:href="@{/css/font.css}" />
	<link rel="stylesheet" th:href="@{/css/xadmin.css}" />
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body class="layui-anim layui-anim-fadein">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a>合作商管理</a>
        <a><cite>合作商列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
          <input id="name" type="text" name="name"   placeholder="名称" autocomplete="off" class="layui-input">
          <div class="layui-input-inline">
            <select id="status" name="status">
              <option value="">全部</option>
              <option value="1">正常</option>
              <option value="0">禁用</option>
            </select>
          </div>
          <button id="searchBtn" data-type="reload" class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
          <button class="layui-btn" style="margin-left: 50px;" onclick="downLoadApiDoc()">对接文档</button>
        </div>
      </div>
      <xblock>
      <button class="layui-btn" onclick="x_admin_show('新增','/admin/partner/addPage.html',495,450)"><i class="layui-icon"></i>新增</button>
      </xblock>
      <table class="layui-hide" id="table1" lay-filter="tool1"></table>
      <script type="text/html" id="bar1">
		{{#  if(d.dispatch_order_status == 1){ }}
 		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="orderFlag">停止派单</a>
		{{#  }else{  }}
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="orderFlag">开启派单</a>
		{{#  }  }}
		{{#  if(d.status == 1){ }}
 		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">禁用</a>
		{{#  }else{  }}
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="del">启用</a>
		{{#  }  }}
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update" onclick="x_admin_show('修改信息','/admin/partner/updatePage.html?id={{d.id}}',465,550)">修改</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove">删除</a>
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateQuota" onclick="x_admin_show('授信额度','/admin/partner/updateQuotaPage.html?id={{d.id}}',465,400)">授信额度</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reset">重置密码</a>
		</script>
      </div>
<script type="text/html" id="statusTpl">
{{#  if(d.status == 1){ }}
<span style="color: green;">正常</span>
{{#  }else{  }}
<span style="color: red;">禁用</span>
{{#  }  }}
</script>
<script type="text/html" id="dispatchOrderStatusTpl">
{{#  if(d.dispatch_order_status == 1){ }}
<span style="color: green;">开启</span>
{{#  }else{  }}
<span style="color: red;">停止</span>
{{#  }  }}
</script>
<script>
function downLoadApiDoc()
{
	 window.open('[[@{/doc/partner_doc.docx}]]'); 
}
      layui.use(['laydate', 'laypage', 'table'], function(){
        var laydate = layui.laydate,
        table = layui.table, //表格
        laypage = layui.laypage; //分页
        //执行一个 table 实例
        table.render({
          elem: '#table1'
          ,height: 650
          ,limit: 14
          ,limits:[14,20,30,40,50,60,70,80,90]
          ,url: '[[@{/admin/partner/list.html}]]' //数据接口
          ,id:'table1'
          ,page: true
          ,cols: [
           [
            {field: 'id', title: 'ID', width:'6%', sort: true, align:'center',fixed: 'left'}
            ,{field: 'name', title: '合作商名称', width: '10%', align:'center'}
            ,{field: 'quota', title: '授信额度', width: '8%', align:'center'}
            ,{field: 'sort', title: '优先级', align:'center', width: '8%'}
            ,{field: 'today_count', title: '今日总单数', width: '8%', align:'center'}
            /* ,{field: 'today_success_count', title: '成功单数', width: '8%', align:'center'} */
            /* ,{field: 'all_amount', title: '总交易额', width: '8%', align:'center'} */
            ,{field: 'yesterday_amount', title: '昨日交易额', width: '8%', align:'center'}
            ,{field: 'today_amount', title: '今日交易额', width: '8%', align:'center'}
            ,{field: 'status', title: '状态', width: '7%',templet:'#statusTpl', align:'center'}
            ,{field: 'dispatch_order_status', title: '派单状态', width: '7%',templet:'#dispatchOrderStatusTpl', align:'center'}
            ,{fixed: 'right', title: '操作',align:'center', toolbar: '#bar1', width:'29%'}
          ]
          ]
        });
        $('#searchBtn').on('click', function(){
        	var index = layer.msg('查询中，请稍候...',{icon: 16,time:false,shade:0});
        	table.reload('table1', {
    	        page: {
    	          curr: 1 //重新从第 1 页开始
    	        }
    	        ,where: {
    	        	'name': $('#name').val(),
    	            'status': $('#status').val()
    	        }
    	      });
        	layer.close(index);
       });
        
      //监听工具条
        table.on('tool(tool1)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data = obj.data //获得当前行数据
          ,layEvent = obj.event; //获得 lay-event 对应的值
          if(layEvent === 'reset'){
              layer.confirm('确认重置吗', function(index){
                $.post('[[@{/admin/partner/resetPassword.html}]]',{'id':data.id},function(data){
              	  layer.close(index);
              	  if(data.code==0)
              	  {
              		 layer.alert(data.msg);
              		  table.reload('table1', {
                	        page: {
                	          curr: 1 //重新从第 1 页开始
                	        }
                	        ,where: {
                	        	'name': $('#name').val(),
                	            'status': $('#status').val()
                	        }
                	      });
              	  }
              	  else
              	  {
              		  layer.msg('重置失败');
              	  }
                })
                //向服务端发送删除指令
              });
            }else if(layEvent === 'remove'){
        	  layer.confirm('确认删除？', function(index){
                  $.post('[[@{/admin/partner/remove.html}]]',{'id':data.id},function(data){
                	  layer.close(index);
                	  layer.msg(data.msg);
                	  if(data.code==0)
                	  {
                		  table.reload('table1', {
                  	        page: {
                  	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                  	        }
                  	        ,where: {
                  	        	'name': $('#name').val(),
                	            'status': $('#status').val()
                  	        }
                  	      });
                	  }
                  })
                  //向服务端发送删除指令
                });
          }else if(layEvent === 'del'){
        	  layer.confirm('确认操作？', function(index){
                  $.post('[[@{/admin/partner/updateStatus.html}]]',{'id':data.id,'status':data.status},function(data){
                	  layer.close(index);
                	  layer.msg(data.msg);
                	  if(data.code==0)
                	  {
                		  table.reload('table1', {
                  	        page: {
                  	          curr: 1 //重新从第 1 页开始
                  	        }
                  	        ,where: {
                  	        	'name': $('#name').val(),
                	            'status': $('#status').val()
                  	        }
                  	      });
                	  }
                  })
                  //向服务端发送删除指令
                });
          }else if(layEvent === 'orderFlag'){
        	  layer.confirm(data.dispatch_order_status==1?'确认停止派单?':'确认开启派单?', function(index){
                  $.post('[[@{/admin/partner/updateDispatchOrderStatus.html}]]',{'id':data.id,'dispatch_order_status':data.dispatch_order_status},function(data){
                	  layer.close(index);
                	  layer.msg(data.msg);
                	  if(data.code==0)
                	  {
                		  table.reload('table1', {
                  	        page: {
                  	          curr: 1 //重新从第 1 页开始
                  	        }
                  	        ,where: {
                  	        	'name': $('#name').val(),
                	            'status': $('#status').val(),
                	            'dispatch_order_status': $('#dispatch_order_status').val(),
                  	        }
                  	      });
                	  }
                  })
                  //向服务端发送删除指令
                });
          }
        });
      });
    </script>
  </body>
</html>
